<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width = device-width , initial-scale = 1 , minimum-scale = 1 , maximum-scale = 1 , user-scalable = no">
    <link rel="stylesheet" href="../../resource/css/bootstrap.min.css">
    <link rel="stylesheet" href="../../resource/css/common.css">
</head>
<body>
<div id="header">
    <a href="javascript:void(0)" class="nav-back">返回</a>
    信息
    <span class="btn-edit">编辑</span>
</div>
<div class="message-content">
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">

            <div class="modal-body">
                test
            </div>

        </div>
    </div>
</div>
<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="../../resource/js/jquery.min.js"></script>

<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="../../resource/js/bootstrap.min.js"></script>
<script src="../../resource/js/commonjs.js"></script>
<script type="text/javascript">
    $(function() {
        isLogin();
        getSystemMsg();
        $(".nav-back").click(function(){
            history.go(-1);
        })
    });
    /* 获取系统消息 */
    function getSystemMsg() {
        var url = "/UserCenter/getSystemMsg";
        var arg = {};
        ajaxJsonp(url, arg, renderSystemMsg);
    }
    /* 渲染msg */
    function renderSystemMsg(res) {
        var data = res.data;
        var html = '';''
        for(var i = 0; i<data.length; i++) {
            var time = new Date(data[i].create_time * 1000).toLocaleDateString();
            time = time.replace(/\//g,".");
            html += '<div class="message">';
            html += '<h1 class="message-title">'+ data[i].content +'</h1>';
            html += '<span class="message-time">'+ time +'</span>';
            html += '<span class="message-check" data-id="'+ data[i].id +'"></span>';
            html += '</div>';
        }
        if(data.length == 0) {
            html += '<h1 class="tips">你没有系统消息</h1>';
        }
        $(".message-content").append(html);
        eventBinding();
    }
    function deleteSuc(res) {
        showModal("删除成功");
    }
    function eventBinding() {
        $('.btn-edit').click(function () {
            var $messageTt = $('.message .message-title');
            var $checkBox =   $('.message-check');

            if($(this).hasClass('btn-delete')) {
                var ids = [];
                $('.message').find('.checked').each(function() {
                    ids.push($(this).attr("data-id"));
                    $(this).parent().remove();
                });
                if(ids.length > 0) {
                    ids = ids.join(",");
                    var url = "/UserCenter/delSystemMsg";
                    var arg = {};
                    arg.id = ids;
                    ajaxJsonp(url, arg, deleteSuc);
                }
            }
            if(! $messageTt.hasClass('edit')) {
                $messageTt.addClass('edit');
                $checkBox.addClass('show');
                $(this).text('删除');
                $(this).addClass('btn-delete');
            } else {

            }
        });
        $('.message').click(function() {
            if($("#header span").hasClass("btn-delete")){
                $(this).find(".message-check").toggleClass('checked');
            }
        });
    }
</script>
</body>
</html>